version 13
#delimit;
clear all;
set more off;
capture log close;


global strformat "%8.3f";

capture program drop sig_p;
program sig_p;
   args obj_var point_est_var point_sd_var p_val row_id_var row_num;
   local point_est `point_est_var';
   local point_sd `point_sd_var';
   if `p_val' > 0.1 {;
      replace `obj_var' = string(`point_est', "$strformat") if `row_id_var' == `row_num';
      };
   if `p_val' > 0.05 & `p_val' <= 0.1  {;
      replace `obj_var' = string(`point_est', "$strformat")+"*" if `row_id_var' == `row_num';
      };
   if `p_val' > 0.01 & `p_val' <= 0.05  {;
      replace `obj_var' = string(`point_est', "$strformat")+"**" if `row_id_var' == `row_num';
      };
   if `p_val' <= 0.01 {;
      replace `obj_var' = string(`point_est', "$strformat")+"***" if `row_id_var' == `row_num';
      };
   replace `obj_var' = "<" + string(`point_sd', "$strformat") + ">" + " " if `row_id_var' == `row_num' + 1;
   end;


*enter directory name here;

use "$dir/ReStat_children.dta", clear;

	
	
global fu_child_controls_cm
	"control_fu_child_age control_fu_female
	missing_fu_child_age missing_fu_female";
		
global fu_hh_controls_cm
	"control_fu_adults control_fu_hh_head_edu control_fu_hh_head_occ_farmer 
	control_fu_total_land control_fu_household_size
	missing_fu_adults missing_fu_hh_head_edu missing_fu_hh_head_occ_farmer 
	missing_fu_total_land missing_fu_household_size";


gen included_sample_govtpprs = 1 if child_enrolled_pprs == 1 |
	(child_enrolled_govt == 1 & pooled_treatment == 0);



gen row_num = _n;


forvalues i=0/25 {;
	generate col`i' = "";
};

local row = 5;
sort row_num;
order col0-col25;


egen fu1c_ht_mud_thatched = rowtotal(fu1c_ht_kaccha fu1c_ht_thatched_huts);


foreach var of varlist 

	fu_child_age fu_female   
	fu_child_of_hh_head
	
	fu_household_size fu_num_children fu_hh_head_edu
	fu_total_land
	
	fu1c_ht_mud_thatched 
	fu_num_goats fu_muslim_fiqa_sunni fu_lang_sindhi {;
	

	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if fu_young_child == 1 & fu_child_level == 1 & pooled_treatment == 0 & fu_child_enrolled == 0  [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	
	xi: regress `var' child_enrolled_govt
		i.bl_district 
		if fu_child_level == 1 & fu_young_child == 1 & pooled_treatment == 0 [pw=hh_weight], cluster(villcode);
	test child_enrolled_govt;
	sig_p col3 _b[child_enrolled_govt] _se[child_enrolled_govt] r(p) row_num `row';


	xi: regress `var' child_enrolled_pprs
		i.bl_district 
		if fu_child_level == 1 & fu_young_child == 1 & included_sample_govtpprs == 1 [pw=hh_weight], cluster(villcode);
	test child_enrolled_pprs;
	sig_p col5 _b[child_enrolled_pprs] _se[child_enrolled_pprs] r(p) row_num `row';

	
	xi: regress `var' pooled_treatment
		i.bl_district 
		if fu_child_level == 1 & fu_young_child == 1 &
		child_enrolled_govt == 1 [pw=hh_weight], cluster(villcode);
	test pooled_treatment;
	sig_p col7 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';
	
	
	local row = `row' + 3;
	

};


local row = `row' + 1;



foreach var of varlist 

	fu_hh_head_occ_landlord fu_hh_head_occ_farmer fu_hh_head_occ_laborer fu_hh_head_occ_teachercivil
		fu_hh_head_occ_other {;
	

	replace col0 = "`var'" if row_num == `row';
	
 	su `var' if fu_young_child == 1 & fu_child_level == 1 & pooled_treatment == 0 & fu_child_enrolled == 0  [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	
	xi: regress `var' child_enrolled_govt
		i.bl_district 
		if fu_child_level == 1 & fu_young_child == 1 & pooled_treatment == 0 [pw=hh_weight], cluster(villcode);
	test child_enrolled_govt;
	sig_p col3 _b[child_enrolled_govt] _se[child_enrolled_govt] r(p) row_num `row';


	xi: regress `var' child_enrolled_pprs
		i.bl_district 
		if fu_child_level == 1 & fu_young_child == 1 & included_sample_govtpprs == 1 [pw=hh_weight], cluster(villcode);
	test child_enrolled_pprs;
	sig_p col5 _b[child_enrolled_pprs] _se[child_enrolled_pprs] r(p) row_num `row';

	
	xi: regress `var' pooled_treatment
		i.bl_district 
		if fu_child_level == 1 & fu_young_child == 1 &
		child_enrolled_govt == 1 [pw=hh_weight], cluster(villcode);
	test pooled_treatment;
	sig_p col7 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';
	
	
	local row = `row' + 3;
	

};



local row = `row' + 1;




outsheet col0-col7 using "$dir/Table A4 child characteristics by school type.csv" if
	row_num < `row', comma replace;
